
<%@page import="beans.*"%>
<%@page import="controladores.*"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>

<%@include file='master/header.jsp'%>
	<form name=cerrarM>
		<h1>Cargar Comanda </h1><br>
		
		<%
		Controlador c = new Controlador();
		%>
		<table>
			<tr>
				<td>Mesa Nro:</td>
				<td><input type="text" name="nroMesa" value='<%=(request.getParameter("nroMesa")==null)?"":request.getParameter("nroMesa")  %>' onkeyup="validaEntero(this)"></td>
			</tr>
			<tr>
				<td>Mozo: </td>
				<td>
				<select name="ddlMozo" id="t1">
					<option></option>
				  	<% 			
				  		for (Mozo m : c.MozosList()){
				  			%><option value='<%=m.getIdMozo()  %>'><%=m.getNombre() %></option><%
				  		}
					%>	
				</select>
				</td>
			</tr>
			<tr>
				<td>Destino: </td>
				<td>
					<select name="ddlDestino" id="t1">
						<option></option>
						<option>Cocina</option>
						<option>Cafeteria</option>
						<option>Barra</option>
				</select>
				</td>
			</tr>
			<tr>
				<td>Cantidad Platos</td>
				<td><input type="text" name="tcantPlatos" value='<%=(request.getParameter("cantPlatos")==null)?"":request.getParameter("cantPlatos")%>' onkeyup="validaEntero(this)"></td>
			</tr>
			<%
			
			
			if (request.getParameter("ddlPlato0")!=null){
				//se cargaron los platos
				List<Object[]> os = new ArrayList<Object[]>();
				Object[] oPlato ;
				for(int i=0;i<20;i++){
					if ((request.getParameter("ddlPlato"+i)!=null) && 
						(request.getParameter("tcantPlatos"+i)!=null)){
						oPlato = new Object[2];
						oPlato[0] = request.getParameter("ddlPlato"+i);
						oPlato[1] = request.getParameter("tcantPlatos"+i);
						os.add(oPlato);
					}
				}
				
				int ddlMozo = Integer.parseInt(request.getParameter("ddlMozo"));
				int nroMesa =Integer.parseInt( request.getParameter("nroMesa"));
				
				
				c.cargarComanda(os,ddlMozo,nroMesa);
					
			}else if (request.getParameter("tcantPlatos")!=null){
				
				%>
				<tr style="background-color:#eee">
						<td style="background-color:#ddd"> </td>
						<td style="background-color:#ddd">	</td>
						<td style="background-color:#ddd">cant	</td>
					</tr>
				<%
				int cantPlatos = Integer.parseInt(request.getParameter("tcantPlatos"));
				for(int i=0;i<cantPlatos;i++){
					%>
					
					<tr style="background-color:#eee">
						<td style="background-color:#ddd">Plato: </td>
						<td style="background-color:#ddd">
							<select name="ddlPlato<%=i %>" id="t1<%=i %>">
								<option></option>
							  	<% 			
							  		
							  		List<Object[]>  lista = c.platosList(request.getParameter("ddlDestino"));
							  		
									//for (int j=0; j<p.size();j++ ){
									for(Object[] o: lista){	
							  			%><option value='<%=o[0]%>'><%=o[1]%></option><%
							  		}
								%>	
						</select>
						</td>
						<td style="background-color:#ddd">
						<input type="text" name="tcantPlatos<%=i %>" value="">
						</td>
					</tr>
					 <%	 
				}					 
			}
			
			 %>
			<tr>
				<td></td>
				<td><input type="submit" name="btnSubmit" value="Aceptar" class="boton" /></td>
			</tr>
		</table>
		 <br>
		
				
	
	
	</form>
<%@include file='master/footer.jsp'%>